<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>AJAX</title>
</head>
<body>
<h1>AJAX Learning</h1>
<button onclick="f()">点我</button>
<p id="demo">aa</p>
<script>
    function f() {
        var httpRequest=new XMLHttpRequest();
        //当请求接收到应答时所执行的函数
        httpRequest.onreadystatechange=function(){
            if(this.status==200){
                alert("请求成功");
            }
        };
        //设置请求，并发送
        httpRequest.open("GET","object.html");
        httpRequest.send();
        document.getElementById("demo").innerHTML = httpRequest.status+":"+httpRequest.statusText;
    }

</script>
</body>
</html>